<?PHP

class OP_ContentBodyWidget extends OP_WidgetTemplate{
	function render(){
		include(TEMPLATEPATH.'/widgets/template.content_body.php');
		render_op_contentbody($this->values['content_layout'], $this->values['advanced']);
	}
	
	function do_post($post){
		$tabs = array();
		for($i = 0; $i < count($post['tab']['tag']); $i++){
			if($post['tab']['tag'][$i] == '') continue;
			$tabs[] = attribute_escape($post['tab']['tag'][$i]);
		}
		
		return array('content_layout'=>$tabs,'advanced'=>$post['advanced']);
	}
	
	// Output options form
	function options(){
		$tags = array('title','author','time','date','post-body','post-excerpt','thumbnail','div','div-close','comments','tags','categories','edit-link','op_content_hook');
		echo '<p>';
		if(count($tags)>0){
			echo '<div style="float:right"><a target="_blank" href="http://onepresscommunity.com/docs/onepress/#admin-widgets-content_body">Help</a></div>', 
				'<div><a href="#" class="op_add_tab_trigger">+ Add component</a></div>',
				'<div class="tab_options" style="display:none">',
				'<a href="#" class="op_remove_tab_trigger">X</a>',
				'<label>Select component: </label>',
				'<select name="widget_op_content_body['.$this->values['number'].'][tab][tag][]">',
				'<option></option>';

			foreach($tags as $value){
				echo '<option value="'.$value.'">'.$value.'</option>';
			}

			echo '</select>',
				'</div>';
		}
		
		echo '<div class="op_current_tabs">';
		if(count($this->values['content_layout'])>0){
			foreach($this->values['content_layout'] as $tab){
				echo '<div class="tab_options">',
					'<a href="#" class="op_remove_tab_trigger">X</a>',
					'<label>Select component: </label><select name="widget_op_content_body['.$this->values['number'].'][tab][tag][]">',
					'<option></option>';
					
				foreach($tags as $value){
					$checked = $tab == $value ? ' SELECTED' : '';
					echo '<option value="'.$value.'"'.$checked.'>'.$value.'</option>';
				}
				echo '</select>',
					'</div>';			
			}	
		}
		
		echo '</div>';
		echo '<a class="op_advanced_options_trigger" href="#">Advanced</a><br/>',
			'<div class="op_advanced_options">',
				'<label>Author Prefix: </label><input type="text" name="widget_op_content_body['.$this->values['number'].'][advanced][author_pre]" value="'.$this->values['advanced']['author_pre'].'"><br/>',
				'<label>Time Prefix: </label><input type="text" name="widget_op_content_body['.$this->values['number'].'][advanced][time_pre]" value="'.$this->values['advanced']['time_pre'].'"><br/>',
				'<label>Time Format: </label><input type="text" name="widget_op_content_body['.$this->values['number'].'][advanced][time_format]" value="'.$this->values['advanced']['time_format'].'"><br/>',
				'<label>Date Format: </label><input type="text" name="widget_op_content_body['.$this->values['number'].'][advanced][date_format]" value="'.$this->values['advanced']['date_format'].'"><br/>',
				'<label>More Link: </label><input type="text" name="widget_op_content_body['.$this->values['number'].'][advanced][more_link]" value="'.$this->values['advanced']['more_link'].'"><br/>',
				'<label>Tag Label: </label><input type="text" name="widget_op_content_body['.$this->values['number'].'][advanced][tag_label]" value="'.$this->values['advanced']['tag_label'].'"><br/>',
				'<label>Tag Before: </label><input type="text" name="widget_op_content_body['.$this->values['number'].'][advanced][tag_before]" value="'.$this->values['advanced']['tag_before'].'"><br/>',
				'<label>Tag Separator: </label><input type="text" name="widget_op_content_body['.$this->values['number'].'][advanced][tag_separator]" value="'.$this->values['advanced']['tag_separator'].'"><br/>',
				'<label>Tag After: </label><input type="text" name="widget_op_content_body['.$this->values['number'].'][advanced][tag_after]" value="'.$this->values['advanced']['tag_after'].'"><br/>',
				'<label>Category Label: </label><input type="text" name="widget_op_content_body['.$this->values['number'].'][advanced][category_label]" value="'.$this->values['advanced']['category_label'].'"><br/>',
				'<label>Category Separator: </label><input type="text" name="widget_op_content_body['.$this->values['number'].'][advanced][category_separator]" value="'.$this->values['advanced']['category_separator'].'"><br/>',
				'<label>Category Parents: </label><input type="text" name="widget_op_content_body['.$this->values['number'].'][advanced][category_parents]" value="'.$this->values['advanced']['category_parents'].'"><br/>',
				'<label>Comment Link None: </label><input type="text" name="widget_op_content_body['.$this->values['number'].'][advanced][comment_link_none]" value="'.$this->values['advanced']['comment_link_none'].'"><br/>',
				'<label>Comment Link One: </label><input type="text" name="widget_op_content_body['.$this->values['number'].'][advanced][comment_link_one]" value="'.$this->values['advanced']['comment_link_one'].'"><br/>',
				'<label>Comment Link Multiple: </label><input type="text" name="widget_op_content_body['.$this->values['number'].'][advanced][comment_link_multiple]" value="'.$this->values['advanced']['comment_link_multiple'].'">',
			'</div>';
		echo '</p>';
	}
	
	/**
	 * Add styles and javascript for widget admin
	 *
	 * @return void
	 * @author Sean
	 **/
	function admin_head(){
		$url = get_bloginfo('template_directory').'/op/admin/';
		//wp_register_script('opfeaturettetabsadminjs', $url.'scripts/featurette_tabs.js',array('jquery','jquery-ui-sortable','opw'));
		//wp_enqueue_script('opfeaturettetabsadminjs');
	}
}

$widget = new OP_Widget('content_body');
$widget->setMeta('OP Content Body','Show content on blog as determined by user');
$widget->setDefaults(array(
	'content_layout'	=> array('title','date','post-body','tags','div','categories','edit-link','comments'),
	'advanced'			=> array(
		'author_pre'		=> 	'by ',
		'time_pre'			=> 	'at ',
		'time_format'		=> 	'',
		'date_format'		=> 	'F j, Y',
		'more_link'			=>	 'Read the rest of this entry &raquo;',
		'tag_label'			=> 	'Tags: ',
		'tag_before'		=> 	'',
		'tag_separator'		=>	', ',
		'tag_after'			=>	'',
		'category_label'	=>	'Categories: ',
		'category_separator'	=>	', ',
		'category_parents'		=> 	'',
		'comment_link_none'		=> 	'No Comments &#187;',
		'comment_link_one'		=>	'1 Comment &#187;',
		'comment_link_multiple'	=>	'% Comments &#187;'
)));
$widget->setAdminDimensions(415,350);

$opw_content_body = new OP_ContentBodyWidget($widget);
add_action('widgets_init', array($opw_content_body, 'init'));
?>